import java.util.ArrayList;

public class SecondaryUser 
{
	private int x;
	private int y;
	private int round_seq;
	private int channel_accessed;
	private ArrayList<Integer> channels;
	private ArrayList<Integer> primary_users_appeared;
	 
		
	SecondaryUser(int max_x_axis, int max_y_axis)
	{
		this.channels = new ArrayList<Integer>();
		this.primary_users_appeared = new ArrayList<Integer>();
		this.x = RandomValue.getRandomValue(max_x_axis);
		this.y = RandomValue.getRandomValue(max_y_axis);
		round_seq = -1;
		this.channel_accessed = -1;
	}
	
	/*
	 * every round, su will check the primary users appeared 
	 */
	private void scan_primary_users()
	{
		this.primary_users_appeared.clear();
		
		for(int i=0; i < PrimaryUsr.primary_users.size(); i++)
		{
			PrimaryUsr p = PrimaryUsr.primary_users.get(i);
			int p_x = p.get_x_axis();
			int p_y = p.get_y_axis();
			
			double distance = Utilis.calDistance(this.x, this.y, p_x, p_y);
			if(Utilis.isNeighbor(distance, Enviroment.get_interference_distance()))
			{
				this.primary_users_appeared.add(p.getID());
			}
		}
	}
	
	/*
	 * 
	 */
	public int run()
	{
		this.scan_primary_users();
		
		//you have to call algorithm to calculate, send them the available chanens
		
		return 0;
	}
	
	public int get_X_axis()
	{
		return this.x;
	}
	
	public int get_Y_axis()
	{
		return this.y;
	}
	
	public int get_round_seq()
	{
		return this.round_seq;
	}
	
	public int get_channel_accessed()
	{
		return this.channel_accessed;
	}
	
	public void set_channels(int num)
	{
		this.channel_accessed = num;
	}

}
